package com.zy.bean4;

import com.zy.bean4.service.ProductService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan
public class App4 {
    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext(App4.class);

        ProductService productService = (ProductService) context.getBean("productServiceImpl");
        productService.add("p1",100);
        productService.update("p1",200);
        double price = productService.findPrice("p1");

        //因为已经 确定要获取的bean的类型是  ProductService , 所以无需类型 转换
        ProductService productService2 =  context.getBean(ProductService.class);
        productService2.add("p1",100);
        productService2.update("p1",200);
         price = productService2.findPrice("p1");


        System.out.println(price);
    }
}
